#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int n;
pii t[N];

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 1, n) t[i].fi = in, t[i].se = in;
	sort(t + 1, t + n + 1, [&](pii x, pii y) {
		return
			x.se * x.fi + y.se * (2 * x.fi + y.fi + 1) < y.se * y.fi + x.se * (2 * y.fi + x.fi + 1);
	});
	ll ans = 0, tim = 0;
	rep(i, 1, n) {
		tim += t[i].fi;
		ans += t[i].se * (tim + i - 1);
		tim += t[i].fi;
		//cerr << t[i].fi << " " << t[i].se << endl;
	} cout << ans << endl;
	return 0;
}
